﻿@using Smarly.Forum.Bussines.Model
@using Smarly.Web.Areas.StapleForum.Helpers
@using Smarly.Web.Helpers
@model Smarly.Forum.Bussines.Model.ThreadModel

@{
	ViewBag.Title = "Index";
}

@{
	ThreadModel.ThreadNote newNote = new ThreadModel.ThreadNote() {ThreadId = Model.Id};
	ThreadModel.ThreadNote insertNote = ViewBag.NewNote as ThreadModel.ThreadNote;

	if (insertNote != null)
	{
		newNote = insertNote;
	}
}

@section css{
	@Html.Partial("_InsertNoteCssPartial")
}
@section script
{

	@Html.Partial("_InsertNoteScriptPartial", newNote)


	@Styles.Render("~/bundles/css/highlight")
	@Scripts.Render("~/bundles/js/highlight")
	<script type="text/javascript">
		$(function() {
			hljs.tabReplace = '  ';
			hljs.lineNodes = true;
			hljs.initHighlightingOnLoad(true);
		});
	</script>
	
	<script type="text/javascript">
		$().ready(function() {
			$('[id^="clarify-form-"]').each(function() {
				clarifyForm($(this));
			});

			$('a.edit-clarify').click(function (e) {
				e.preventDefault();

				var $this = $(this);
				var $div = $this.closest('div');
				var $p =  $('p', $div).hide();

				var $form = $('<form method="post"><textarea rows="2" name="Value" id="Value" cols="20"></textarea><label generated="true" for="Value" class="error"></label><div class="right"><input type="submit" value="Обновить" class="btn"><input type="submit" value="Отменить" class="btn cancel"></div></form>');

				$('input.cancel', $form).click(function(e) {
					e.preventDefault();
					$(this).off();
					$form.closest('p').remove();
					$('p', $div).show();
				});

				$form.attr('action', $this.attr('href'));
				$('textarea', $form).val($('span.value', $p).text());

				clarifyForm($form);
				$div.prepend($('<p/>').append($form));

			});
		});

		function clarifyForm($form) {
			var url = $form.attr('action');

			var rules = {};
			rules[url] = {
				'@Html.IdFor(x => x.Value)': { required: true, },
			};

			var messages = {};
			messages[url] = {
				'@Html.IdFor(x => x.Value)': { required: "Поле не заполнено", },
			};

			$form.smarlyValidation({
				ext: {
					rules: rules,
					messages: messages,
				},
				onSuccess: function(data) {
					document.location.reload(true);
				}
			});

		}
	</script>
}


@{
	var section = Model.SectionHashTag.GetSection();
}


@Html.Action("Crumbs", "Section", new {section = Model.SectionHashTag})

@Html.Partial("_GoogleAdsPartial")

<div class="row-fluid">
	<div class="span12">
		<div class="block-white">
			<div class="block-content">
				<div>@Html.ActionLink("Вернуться к списку веток в разделе \"" + section.Name + "\"", "Section", "Home", new { section = Model.SectionHashTag }, new { })</div>
			</div>
		</div>
	</div>
</div>

@{
	ViewBag.Title = Model.Title;
	ViewBag.ThreadId = Model.Id;
	ViewBag.Section = Model.SectionHashTag;
}

@foreach (var note in Model.Notes)
{
	@Html.Partial("_ThreadNotePartial", note)
}

@Html.Partial("_InsertNotePartial", newNote)



